use std::io;
use rand::Rng;
use std::cmp::Ordering;


fn main() {
    let rand_number = rand::thread_rng().gen_range(1,101);

    // println!("rand number is : {} ",rand_number);

    // println!("Please input your guess :");


    loop {
        let mut guess : String = String::new();
        //io::stdin().read_line(&mut guess).expect("read fail");
        match io::stdin().read_line(&mut guess){
            Ok(_) => {},
            Err(_) => {println!("read fail!");continue}
        };

        // trim 消除换行符 parse 转为数字
        //let guess:u32 = guess.trim().parse().expect("Not a Number!");
        let guess:u32 = match guess.trim().parse() {
            Ok(num) => {num},
            Err(_) => {println!("Not a Number");continue}
        };

        match guess.cmp(&rand_number) {
            Ordering::Less => {println!("Too Less!");},
            Ordering::Greater => {println!("Too Greater");},
            Ordering::Equal =>{println!("You Win");break;},
        }
    }
    


    //println!("Your guess is : {}",guess)
}
